<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>出库登记审核</title>
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap-table.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="../../js/bootstrap-table.min.js"></script>
    <script src="../../js/bootstrap.min.js"></script>
    <script src="../../js/bootstrap-table-zh-CN.min.js"></script>
    <script>
        $(function () {

            $("#EBchecktab").bootstrapTable({
                method: "get",
                contentType: "application/json;charset=utf-8",
                url: "/spay/queryOutboundCheck",
                striped: true,
                pageNumber: 1,
                pagination: true,
                sidePagination: 'server',
                pageSize: 5,
                pageList: [3, 5, 6, 10],
                queryParams: function (params) {
                    return {
                        // 计算页号(当前页)
                        pageNumber: (params.offset / params.limit) + 1,
                        // 计算页大小
                        pageSize: params.limit,
                    }
                },
                columns: [
                    {title: '出库单编号', field: 'payId', align: 'center'},
                    {title: '出库理由', field: 'reason', align: 'center', formatter: function (value, row, index) {
                            if (value == "c002-1") {
                                return "生产领料";
                            } else if (value == "c002-2") {
                                return "赠送";
                            } else if (value == "c002-3") {
                                return "内部借领";
                            } else if (value == "c002-4") {
                                return "其他借领"
                            } else {
                                return "其他";
                            }
                        }
                    },
                    {title: '出库详细理由',field: 'reasonexact',align: 'center'},
                    {title: '登记时间',field: 'registerTime',align: 'center'},
                    {title: '总件数', field: 'amountSum', align: 'center'},
                    {title: '总金额', field: 'costPriceSum', align: 'center'},
                    {title: '审核',field: 'id',align: 'center',
                        formatter: function (value, row, index) {
                            var btn1="<button  class='btn btn-primary btn-sm'  data-toggle='modal' data-target='#myModal2' onclick='chehck("+JSON.stringify(row)+",2)'>审核</button>";
                            return btn1;
                        }
                    },
                ]
            })
        });
        function findAcc() {
            $.ajax({
                type: 'post',
                url: '/SysUser/queryUser',
                success: function (result) {
                    $("#register").val(result.loginId);
                }
            })
        }
        function findcost_price_sum(val) {
            $.ajax({
                type:'post',
                url:'/spay/querySpayTotalcost',
                data:'id='+val,
                success:function (result) {
                    $("#costPrice_Sum").val(result);
                }
            })
        }

        function chehck(data,s) {
            findAcc();
            findcost_price_sum(data.id);
            console.log(data.id)
            $("#id").val(data.id);
            $("#payId").val(data.payId);
            var re='';
            if (data.reason == "c002-1") {
                re= "生产领料";
            } else if (data.reason == "c002-2") {
                re= "赠送";
            } else if (data.reason == "c002-3") {
                re= "内部借领";
            } else if (data.reason == "c002-4") {
                re= "其他借领"
            } else {
                re= "其他";
            }
            $("#reason").val(re);
            $("#amountSum").val(data.amountSum);
            $("#costPriceSum").val(data.costPriceSum);
            $("#register_time").val(new Date().toLocaleString());
            $("#amount_Sum").val(data.paidAmountSum);
            $("#table5").bootstrapTable("destroy");
            $("#table5").bootstrapTable({
                method: "get",
                contentType: "application/json;charset=utf-8",
                url: "/spay/findSpayDetailsByIdandQuantityIinStorage",
                queryParams: function (params) {
                    return {
                        id:data.id,
                    }
                },
                columns: [
                    {title: '产品编号', field: 'product_id', align: 'center',formatter:function (value,row,index) {
                            return "<span class='productId'>"+value+"</span>"
                        }},
                    {title: '产品名称', field: 'product_name', align: 'center'},
                    {title: '库房名称', field: 'id',align: 'center',formatter:function (value,row,index) {
                            return "成品房"
                        }},
                    {title: '当前库存数量', field: 'number', align: 'center'},
                    {title: '应出库件数', field: 'amount', align: 'center'},
                    {title: '已出库件数', field: 'paid_amount', align: 'center',formatter:function (value,row,index) {
                            if(value==null){
                                return 0;
                            }else{
                                return  value;
                            }
                        }},
                    {
                        title: '本次出库数量', field: 'quantity_in_storage', align: 'center',formatter:function (value,row,index) {
                            return "<span class='sl'>"+value+"</span>"
                        }
                    },
                    {title: '序列号',field: 'id',align: 'center',formatter:function (value,row,index) {
                            return "<span class='id'>"+value+"</span>"
                        }}
                ]
            })
        }
        function commitRk() {
            var list=[];
            var slList=$(".sl");
            var idList=$(".id");
            var pIdList=$(".productId");
            $.each(slList,function (index,value) {
                console.log(slList[index].innerText);
                console.log(idList[index].innerText);
                var obj= {
                    productId:pIdList[index].innerText,
                    id: idList[index].innerText,
                    quantityInStorage: slList[index].innerText,
                }
                list.unshift(obj);

            })
            console.log(JSON.stringify(list))
            $.ajax({
                type:'post',
                url:'/spay/OutboundCheckPass',
                contentType:'application/json;',
                data:JSON.stringify({
                    spay:{
                        id:$("#id").val(),
                        payId:$("#payId").val()
                    },
                    list:list
                }),
                success:function (result) {
                    if(result==1){
                        alert("审核成功");
                        window.location.reload();
                    }
                }
            })
        }
    </script>
</head>
<body>
<table id="EBchecktab" class="table">

</table>

<div class="modal fade" id="myModal2">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title" style="margin-left: 43%;">出库单</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">
                <input type="hidden" id="id">
                <div>
                    <div class="form-inline row" style="margin-left: 5%">
                        <span class="">&nbsp;&nbsp;&nbsp;出库单编号：</span>
                        <input type="text" readonly id="payId" class="form-control col-3 gatherId">
                        <div class="col-2"></div>
                        <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;出库理由：</span>
                        <input id="reason" readonly class="form-control col-3">
                        </input>
                    </div>

                </div>

                <table id="table5" class="table tab-content table-hover" style="margin-top: 20px;border: 1px black solid">

                </table>


                <div class="form-inline row" style="margin-top: 20px;margin-left: 5% ">
                    <span class="">应出库总件数：</span>
                    <input type="text" readonly id="amountSum" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">已出库总件数：</span>
                    <input type="text" value="0" readonly id="amount_Sum" class="form-control col-3">
                </div>
                <div class="form-inline row" style="margin-top: 20px ;margin-left: 5%">

                    <span class="">应出库总成本：</span>
                    <input type="text"   readonly id="costPriceSum" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">已出库总成本：</span>
                    <input id="costPrice_Sum" value="0" readonly type="text" class="form-control col-3">
                </div>
                <div class="form-inline row" style="margin-top: 20px;margin-left: 5% ">

                    <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;复核人：</span>
                    <input type="text" readonly id="register" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;复核时间：</span>
                    <input type="text" value="0" readonly id="register_time" class="form-control col-3">
                </div>

            </div>



            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="commitRk()" data-dismiss="modal">提交</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>